rebol[]

do %libs.r

get-bean: func[test-file /save /local data][
either probe system/script/args [
    set-modes system/ports/input [binary: true]
    data: as-string copy system/ports/input
    make-dir first split-path test-file
    write test-file data
] [
    data: read test-file
]
load-bean data
]

load-bean: func[string][
 beans-to-rebol top-array load-xml string
]

mold-bean: func[blk][
 wrap-xml mold-xml-body to-bean-result rebol-to-beans blk
]

mold-bean-result: func[blk][
 join "-bean-result-^/" mold-bean blk
]

data: get-bean/save %test/server.xml
set needed: [server] none
parse data [
 'server set server integer!
]
if not all needed[
 make error! join "wrong arguments" mold data
]

request: func[blk /local qry port data][
qry: mold-bean blk
probe length? qry
port: open join tcp://localhost: server
insert port rejoin["" length? qry "^/" qry "^/"]
data: load-bean copy port
close port
data
]

res1: request ["request" 1]
res2: request ["request" 2]
data: reduce[res1 res2]

print mold-bean-result reduce['got-reply mold data]
